<?php
/*
Supporting AJAX script for the Tan Tan Noodles Version Checking plugin
*/
if (!is_numeric($_GET['projectID'])) {
    echo 'Invalid ID';
    exit;
}
if (!($_GET['version'])) {
    echo 'Invalid version';
    exit;
}

require_once(dirname(__FILE__).'/../wp-config.php');
$updates = array();
$projectID = (int) $_GET['projectID'];
$hasUpdate = false;
$download = '';
$currentVersion = get_post_meta($projectID, 'version', true);
if (version_compare($currentVersion, $_GET['version'], '>')) {
    $hasUpdate = true;
    $download = get_post_meta($projectID, 'link-download', true);
}
query_posts('page_id='.$_GET['projectID']);
the_post();
?>
<script type="text/javascript">
<?php if ($hasUpdate):?>
printUpdateNotice('<?php echo $_GET['projectID']?>', '<?php echo addslashes(get_the_title());?>', '<?php the_permalink();?>', '<?php echo $_GET['version'];?>', '<?php echo $currentVersion;?>', '<?php echo $download;?>');
<?php else:?>
printNoUpdates('<?php echo $_GET['projectID']?>', '<?php echo addslashes(get_the_title());?>', '<?php the_permalink();?>', '<?php echo $_GET['version'];?>', '<?php echo $currentVersion;?>');
<?php endif;?>
</script>